package com.hdd.art.biz.show.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdd.art.biz.show.dto.AgreementVo;
import com.hdd.art.biz.show.entity.ArtShow;
import com.hdd.art.biz.show.entity.ArtShowSetup;
import com.hdd.art.biz.show.entity.Showroom;
import com.hdd.art.biz.show.mapper.ArtShowSetupMapper;
import com.hdd.art.biz.show.service.ArtShowService;
import com.hdd.art.biz.show.service.ArtShowSetupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdd.art.biz.show.service.ShowroomRuleService;
import com.hdd.art.biz.show.service.ShowroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-07-10
 */
@Service
public class ArtShowSetupServiceImpl extends ServiceImpl<ArtShowSetupMapper, ArtShowSetup> implements ArtShowSetupService {


    @Autowired
    private ShowroomRuleService showroomRuleService;
    @Autowired
    private ShowroomService showroomService;
    @Autowired
    private ArtShowService artShowService;


    @Override
    public ArtShowSetup findArtShowSetup(String artId) {
        QueryWrapper<ArtShowSetup> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("art_id",artId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public void add(ArtShowSetup artShowSetup) {

        baseMapper.insert(artShowSetup);
    }

    @Override
    public void update(ArtShowSetup artShowSetup) {

        baseMapper.updateById(artShowSetup);
    }


    @Override
    public AgreementVo agreement(String artId) {
        AgreementVo agreementVo = new AgreementVo();
        agreementVo.setShowSetup(findArtShowSetup(artId));

        List<Showroom> showrooms =  showroomService.findShowroomByArtId(artId);
        for(Showroom room:showrooms){
            room.setShowroomRule(showroomRuleService.find(room.getId()));
        }

        ArtShow artShow =  artShowService.findArtShowById(artId);
        if(artShow!=null){
            agreementVo.setName(artShow.getName());
        }
        agreementVo.setRules(showrooms);
        return agreementVo;
    }


}
